package com.itheima.chap05;

import java.time.Duration;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class DurationDemo {
    public static void main(String[] args) {
        // 1.录入出生的年月日
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入开始时间(2000-01-01)：");
        String birthdayStr = sc.next();

        // 2.将字符串时间转化为LocalDate对象
        LocalDate birthday = LocalDate.parse(birthdayStr);

        // 3.获取当前时间
        LocalDate now = LocalDate.now();
        // 4.计算用户下一次过生日的时间
//        LocalDate preBirth = LocalDate.of(now.getYear(), birthday.getMonth(), birthday.getDayOfMonth());
        LocalDate nextBirthday = birthday.withYear(now.getYear());
        if (nextBirthday.isBefore(now)){
            nextBirthday = nextBirthday.plusYears(1);
        }
        System.out.println("下个生日：" + nextBirthday);

        // 5.计算用户距离下一次过生日的时间还有多少天
        Duration duration = Duration.between(now.atStartOfDay(), nextBirthday.atStartOfDay());
        System.out.println("距离生日的时间：" + duration.toDays() + "天");
    }
}
